package com.hzjq.fxlib.presenter

import android.view.KeyEvent
import android.view.ViewGroup
import com.hzjq.core.bean.ErrorCapEntity
import com.hzjq.fxlib.R
import com.hzjq.fxlib.ui.ErrorCapActivity
import kotlinx.android.synthetic.main.layout_charge_error.view.*

class ChargeErrorPresenter : AbsViewPresenter {

    private var isEnd = false
    private var errorCap = arrayListOf<ErrorCapEntity>()

    constructor(rootView: ViewGroup) : super(rootView)

    override fun onContentViewId(): Int {
        return R.layout.layout_charge_error
    }

    override fun onResume() {

    }

    override fun showAction(action: String) {
        rootView.chargeErrorText.text = action
    }

    fun isScanEnd(isEnd:Boolean,errorCap:MutableList<ErrorCapEntity>){
        this.isEnd = isEnd
        this.errorCap.clear()
        this.errorCap.addAll(errorCap)
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if(isEnd && (keyCode == KeyEvent.KEYCODE_F1 ||  keyCode == KeyEvent.KEYCODE_F5)){
            ErrorCapActivity.start(getContext(),errorCap)
            return true
        }
        return super.onKeyDown(keyCode, event)
    }
}
